<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>仁兄の博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="做自己爱做的事，爱自己在做的事！">
<meta property="og:type" content="website">
<meta property="og:title" content="仁兄の博客">
<meta property="og:url" content="http://sghuangrihuang.github.io/index.html">
<meta property="og:site_name" content="仁兄の博客">
<meta property="og:description" content="做自己爱做的事，爱自己在做的事！">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="仁兄の博客">
<meta name="twitter:description" content="做自己爱做的事，爱自己在做的事！">
  
    <link rel="alternate" href="/atom.xml" title="仁兄の博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">仁兄の博客</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">记录我在web前端开发之中所遇到的问题</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://sghuangrihuang.github.io"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main">
  
    <article id="post-WEB移动端技巧" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2017/06/12/WEB移动端技巧/" class="article-date">
  <time datetime="2017-06-12T11:02:19.000Z" itemprop="datePublished">2017-06-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2017/06/12/WEB移动端技巧/">WEB移动端技巧</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="移动端布局"><a href="#移动端布局" class="headerlink" title="移动端布局"></a>移动端布局</h2><p>一般在写移动端项目我都采用的是Flex+rem布局，以这种模式布局的话就可以解决我们在移动端项目实现的各种问题。</p>
<h3 id="flex布局"><a href="#flex布局" class="headerlink" title="flex布局"></a>flex布局</h3><p>为什么要用Flex布局呢，在传统的PC端布局中，我们最喜欢用的是float+postion等等，有时候要自适应移动端的布局中，存在各种问题。所以推荐使用flex，在这我推荐阮一峰老师的<a href="http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicool" title="flex布局" target="_blank" rel="external">《Flex 布局教程：语法篇》</a>文章</p>
<h3 id="rem"><a href="#rem" class="headerlink" title="rem"></a>rem</h3><p>CSS3的出现，他同时引进了一些新的单位，包括我们今天所说的rem单位。在W3C官网上是这样描述rem的——“font size of the root element”！也就是说它根据html根元素的字体大小变而改变的，当然与之对应的是em单位，em单位是以所在的父元素的字体大小而变的;<br>这是我的rem配置，根据媒体查询要改变html字体大小进而做到自适应布局</p>
<blockquote>
<p>方法一:</p>
</blockquote>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">html &#123;</div><div class="line">    font-size: 12px;</div><div class="line">&#125;</div><div class="line">@media(min-width:319px) and (max-width: 359px) &#123;</div><div class="line">    html &#123;</div><div class="line">        font-size: 100px!important; /*1rem=100px*/</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line">@media(min-width:360px) and (max-width: 399px) &#123;</div><div class="line">    html &#123;</div><div class="line">        font-size: 112.5px!important; /*1rem=112.5px*/</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line">@media(min-width:400px) and (max-width: 639px) &#123;</div><div class="line">    html &#123;</div><div class="line">        font-size: 125px!important; /*1rem=125px*/</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line">@media(min-width:640px) and (max-width: 768px) &#123;</div><div class="line">    html &#123;</div><div class="line">        font-size: 200px!important; /*1rem=200px*/</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>这是根据我平常移动端设计稿项目(尺寸640宽度)，当然还要根据我使用的前端编辑器Sublime Text有个cssrem插件，可以用px-&gt;rem单位，这里就是使用640宽度的字体大小为200px  那么我设置cssrem插件的时候是以640宽度为基准的 比如设计稿上48px 我直接写48px 自动转为0.24rem; 预览的时候320尺寸 对应就是100*0.24rem = 24px;</p>
<blockquote>
<p>方法二:</p>
</blockquote>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">html&#123;</div><div class="line">    font-size:12px;</div><div class="line">&#125;</div><div class="line">@media(min-width:319px) and (max-width: 768px) &#123;</div><div class="line">    html &#123;</div><div class="line">        font-size:calc(100vw/3.2);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>这个相对方法一简单语法，实际上效果的一样的，不过这种写法更能够适应手机的各个尺寸，但兼容性还有待优化等。其中calc（）这里是一个计算函数，100vw就是说我们屏幕的宽度（等价于设备宽度）q其中 1vw=(device-width)/100 ;  比如640的宽度 640/3.2=200px 这样跟我们方法一一致的 只是写法不同罢了。</p>
<blockquote>
<p>方法三:</p>
</blockquote>
<p>如果方法一、二都不符合大家的要求的话，那就用js吧。</p>
<h3 id="设置移动端宽高度相等"><a href="#设置移动端宽高度相等" class="headerlink" title="设置移动端宽高度相等"></a>设置移动端宽高度相等</h3><p>在移动端项目中，往往一些详情页中，图片一般般往往显示在最上面而且宽高相等的正方形图片，要自适应手机屏幕的时候，大家常用的方法就是宽度 width:100%;（这个方法的前提就是图片宽高相等的情况下），但有没有想到如果图片宽高不相等，或者说一个设计稿的内容板块div宽高相等的情况下，难道用js么？这样很麻烦，实际上不用，废话那么多上css代码</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="selector-class">.img-wrapper</span> &#123;</div><div class="line">    <span class="attribute">position</span>: relative;</div><div class="line">    <span class="attribute">width</span>: <span class="number">100%</span>;</div><div class="line">    <span class="attribute">height</span>: <span class="number">0</span>;</div><div class="line">    <span class="attribute">padding-top</span>: <span class="number">100%</span>;</div><div class="line">&#125;</div><div class="line"><span class="selector-class">.img-wrapper</span>&gt;<span class="selector-tag">img</span>,</div><div class="line"><span class="selector-class">.img-wrapper</span>&gt;<span class="selector-tag">div</span>&#123;</div><div class="line">    <span class="attribute">position</span>: absolute;</div><div class="line">    <span class="attribute">left</span>: <span class="number">0</span>;</div><div class="line">    <span class="attribute">top</span>: <span class="number">0</span>;</div><div class="line">    <span class="attribute">width</span>: <span class="number">100%</span>;</div><div class="line">    <span class="attribute">height</span>: <span class="number">100%</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>至于width: 100%;大家都很明白 主要是height:0; padding-top:100%; 为什么要设置高度为0呢，很明显我要的是宽度和高度相等100%！如果设置高度为100%的时候那就不行了，毕竟高度100%不是根据宽度来计算的。设置高度为0主要的是为了让padding-top属性设置100%值的时候，让这个属性根据宽度计算，这样就完全宽高相等的样式操作了。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://sghuangrihuang.github.io/2017/06/12/WEB移动端技巧/" data-id="cj3u1kzb600000w0xqwz5y4lq" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-hello-world" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2017/05/12/hello-world/" class="article-date">
  <time datetime="2017-05-12T03:19:13.417Z" itemprop="datePublished">2017-05-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2017/05/12/hello-world/">Hello World</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>Welcome to <a href="https://hexo.io/" target="_blank" rel="external">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="external">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="external">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="external">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo new <span class="string">"My New Post"</span></div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="external">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo server</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="external">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo generate</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="external">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo deploy</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="external">Deployment</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://sghuangrihuang.github.io/2017/05/12/hello-world/" data-id="cj3u1kzbm00010w0xyo25y80i" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  
    <article id="post-hello" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2017/03/11/hello/" class="article-date">
  <time datetime="2017-03-11T03:34:02.000Z" itemprop="datePublished">2017-03-11</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="article-title" href="/2017/03/11/hello/">测试</a>
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">$ cnpm install 4</div><div class="line">$ cnpm install 3</div><div class="line">$ cnpm install 2</div><div class="line">$ cnpm install 1</div></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://sghuangrihuang.github.io/2017/03/11/hello/" data-id="cj3u1kzc100020w0x8etgci1e" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
</article>


  

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">六月 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/">三月 2017</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/06/12/WEB移动端技巧/">WEB移动端技巧</a>
          </li>
        
          <li>
            <a href="/2017/05/12/hello-world/">Hello World</a>
          </li>
        
          <li>
            <a href="/2017/03/11/hello/">测试</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 黄日煌<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>

  </div>
</body>
</html>